package com.auxgroup.hr.front.site.co.hireperson;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import com.auxgroup.hr.front.site.vo.person.HireFileTypeRespVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.auxgroup.hr.front.commons.vo.BaseResponseVO;
import com.auxgroup.hr.front.dao.domain.PsCHireFileTbl;
import com.auxgroup.hr.front.dao.domain.PsCHireFileVw;
import com.auxgroup.hr.front.dozer.IObjectMapper;
import com.auxgroup.hr.front.service.hireperson.HireFileService;
import com.auxgroup.hr.front.service.hireperson.HireFileVwService;
import com.auxgroup.hr.front.site.co.BaseCO;
import com.auxgroup.hr.front.site.vo.person.HireFileTypeRespVO;

/**
 * 入职人员文件类型CO
 * @author lvliuhao
 * @version 创建时间：180526 
 */
@RestController
@RequestMapping("${auxgroup.hr.contextPath}/hireFileVw")
public class HireFileVwCO extends BaseCO {

	private static final Logger logger = LoggerFactory.getLogger(HireFileVwCO.class);

	@Autowired
	public HireFileVwService hireFileVwService;
	
	@Autowired
	private HireFileService hireFileService;

	@Resource(name = "dozerMapper")
	protected IObjectMapper objectMapper;
	
	/**
	 * 获取全部
	 * @param rsHireId
	 * @return
	 */
	@GetMapping(value = "/getAll")
	public BaseResponseVO getAll(String rsHireId){
		logger.info("getAllFile type rsHireId={}",rsHireId);
		List<PsCHireFileVw> list = hireFileVwService.getAll();
		List<PsCHireFileTbl> files = null;
		List<HireFileTypeRespVO> responVos = new ArrayList<HireFileTypeRespVO>();
		if(!list.isEmpty()){
			for (PsCHireFileVw fileVw : list) {
				HireFileTypeRespVO responvo = objectMapper.map(fileVw, HireFileTypeRespVO.class);
				files = hireFileService.getAll(rsHireId, fileVw.getcFileNum());
				if(files!=null&&!files.isEmpty()){
					responvo.setUploaded(true);
				}
				responVos.add(responvo);
			}
		}
		return buildRespone(responVos);
	}
	
	

}
